package logic

import (
	"context"
	"errors"
	"shoppingcart-srv/model/mysql"

	"shoppingcart-srv/internal/svc"
	"shoppingcart-srv/shoppingcart"

	"github.com/zeromicro/go-zero/core/logx"
)

type RemoveCartAllLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRemoveCartAllLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RemoveCartAllLogic {
	return &RemoveCartAllLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RemoveCartAllLogic) RemoveCartAll(in *shoppingcart.RemoveCartAllRequest) (*shoppingcart.RemoveCartAllResponse, error) {
	// todo: add your logic here and delete this line
	c := mysql.Cart{
		UserId: in.UserId,
	}
	err := c.RemoveAll()
	if err != nil {
		return nil, errors.New("购物车清空商品失败")
	}
	return &shoppingcart.RemoveCartAllResponse{Success: true}, nil
}
